{include file="header.html"}
<body>

{if $is_app!=1}
<div class="navBar">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView">{if isset($id) && $id>10}发现详情{else}{if $id==1}关于我们{elseif $id==2}帮助中心{elseif $id==3}用户协议{else}详情{/if}{/if}</div>
</div>
{/if}

{if isset($id) && $id>10}
<div class="discover-detail main-padding-top width-wrap">
	<div class="pullRefresh">
		<div class="titleView gr">
			<div class="title">{$data->title}</div>
			<div class="time"><span>{$data->add_time}</span></div>
		</div>
		<div class="content">
			{nl2br($data->content)}
		</div>
		<div class="zanView gr">
			<div class="view">
				<i></i>
				<a href="javascript:void(0)" class="zan"><span>{$data->likes}</span></a>
				<ul>
					{if is_array($data->likes_list) && count($data->likes_list)}
					{foreach from=$data->likes_list name=g item=g}
					<li {if $g->avatar!=''}style="background-image:url({$g->avatar});"{/if}></li>
					{/foreach}
					{/if}
				</ul>
			</div>
		</div>
		{if is_array($data->goods)}
		<ul class="goodsView">
			{foreach from=$data->goods name=g item=g}
			<li class="ge-bottom ge-light">	
				<a href="wap.php?app=goods&act=detail&goods_id={$g->id}">
					<div {if $g->default_pic!=''}style="background-image:url({$g->default_pic});"{/if}></div>
					<span><h1>{$g->name}</h1></span>
					<font><h1>￥{$g->price}</h1></font>
				</a>
			</li>
			{/foreach}
			<div class="qi"></div>
		</ul>
		{/if}
		<div class="commentView ge-bottom ge-light">用户评论 <span>({$data->comments})</span></div>
		<ul class="list">
			{if is_array($data->comments_list) && count($data->comments_list)}
			{foreach from=$data->comments_list name=g item=g}
			<li class="ge-bottom ge-light">
				<div class="infoView">
					<font>{$g->add_time}</font>
					<div {if $g->avatar!=''}style="background-image:url({$g->avatar});"{/if}></div>
					<span>{$g->member_name}</span>
				</div>
				<div class="memo">{$g->content}</div>
			</li>
			{/foreach}
			{/if}
		</ul>
	</div>
	
	<div class="commentPost toolBar ge-top">
		<div>
			<a href="javascript:void(0)"></a>
			<form method="post" action="api.php?app=article&act=post_comment">
			<input type="hidden" name="gourl" value="wap.php?app=article&act=detail&id={$data->id}&discover=1" />
			<input type="hidden" name="article_id" value="{$data->id}" />
			<span><input type="text" name="content" id="content" /></span>
			</form>
		</div>
	</div>
</div>
{else}
<div class="article-detail {if $is_app!=1}main-top{/if}">
	{$data->content}
</div>
{/if}

{include file="footer.html"}
{if isset($id) && $id>10}
<script type="text/javascript" src="js/emojiView/emojiView.js"></script>
<script>
var emojiView = null;
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li class="ge-bottom ge-light">\
		<div class="infoView">\
			<font>'+g.add_time+'</font>\
			<div '+(g.avatar!=''?'style="background-image:url('+g.avatar+');"':'')+'></div>\
			<span>'+g.member_name+'</span>\
		</div>\
		<div class="memo">'+g.content+'</div>\
	</li>';
	offset++;
	return html;
}
function setEmoji(){
	$('.list .memo').emojiView();
	//setTimeout(function(){ $('.list .memo').emojiView(true) }, 3000); //反解析
}
function myFn(){
	if(!$.checklogin())return;
	if(!$('#content').val().length){
		$.overloadError('请输入您的评论');
		return;
	}
	$('form').submit();
}
$(function(){
	setEmoji();
	emojiView = $.emojiView({
		selectFn : function(mark){
			$('#content').val($('#content').val()+mark);
		},
		deleteFn : function(){
			$('#content').deleteEmoji();
		},
		sendFn : function(){
			myFn();
		}
	});
	$('.commentPost a').click(function(){
		if(emojiView.isAppear){
			emojiView.close('.commentPost');
		}else{
			emojiView.show('.commentPost');
		}
	});
	$('.discover-detail').height($.window().height-$('.discover-detail').padding().top-$('.discover-detail').padding().bottom);
	$('#content').placeholder('请输入您的评论').onkey({
		callback : function(code){
			if(code==13)myFn();
		}
	});
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=article&act=detail&id={$id}', function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.comments_list))for(var i=0; i<json.data.comments_list.length; i++)html += createHtml(json.data.comments_list[i]);
				_this.find('.list').html(html);
				setEmoji();
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=article&act=index&id={$id}', { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.comments_list))for(var i=0; i<json.data.comments_list.length; i++)html += createHtml(json.data.comments_list[i]);
				_this.find('.list').append(html);
				setEmoji();
				fn();
			});
		}
	});
});
</script>
{/if}